import java.util.ArrayList;

import javax.swing.table.*;

public class MyTableModel extends DefaultTableModel{
    private ArrayList<Integer> editedIndex = new ArrayList<>();

    MyTableModel(){
        super();
    }
    /**
    * 设置第0项无法修改，否则会出现键值不匹配的现象
    * */
    public boolean isCellEditable(int row,int column){
        return column != 0;
    }
    //重写方法，修改editedIndex
    public void setValueAt(Object aValue,int row,int column){
        super.setValueAt(aValue, row, column);
        int i,count = editedIndex.size();
        if(count==0)
            editedIndex.add(row);
        else{
            for(i=0;i<count;i++){
                if(editedIndex.get(i) >row){
                    editedIndex.add(i+1,row);
                    break;
                }
            }
            if(i>=count)
                editedIndex.add(row);
        }
    }
    ArrayList<Integer> getEditedIndex(){
        return editedIndex;
    }
}

